// VibrationTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <nled.h>
#include "gtest/gtest.h"
using namespace std;

#define VIBRATE_LED				2

class Vibration
{
private:
	UINT16	KBD_BLT_ON;
	UINT16 KBD_BLT_OFF;
	void SetLED (int led, int val) 
	{
		static NLED_SETTINGS_INFO ledsetting;  
		memset(&ledsetting,0,sizeof(ledsetting));
		ledsetting.LedNum=led;  
		ledsetting.OffOnBlink=val;
		NLedSetDevice( NLED_SETTINGS_INFO_ID , &ledsetting);
		return;
	}
	int GetLED (int led) 
	{
		int val;
		static NLED_SETTINGS_INFO ledsetting;  
		memset(&ledsetting,0,sizeof(ledsetting));
		ledsetting.LedNum=led;  
		NLedGetDeviceInfo( NLED_SETTINGS_INFO_ID , &ledsetting);
		val=ledsetting.OffOnBlink;
		return val;
	}

	int GetNumLEDs ( void ) 
	{
		static NLED_COUNT_INFO ledcount;
		NLedGetDeviceInfo( NLED_COUNT_INFO_ID , &ledcount);
		return (int)ledcount.cLeds;
	}

public:
	int initial()
	{
		KBD_BLT_ON = 0x1;
		KBD_BLT_OFF = 0x0;
		cout<<"reset the vibration"<<endl;
		SetLED(VIBRATE_LED,false);
		cout<<"done!";
		cout<<endl<<"------------------------------------------------------"<<endl;
		return 1;
	}

	int vibrate()
	{
		cout<<"vibrate..."<<endl;
		for(int i=0;i<5;++i)
		{
			SetLED(VIBRATE_LED,true);
			Sleep(0.5*1000);
			SetLED(VIBRATE_LED,false);
			Sleep(0.5*1000);
		}
		cout<<endl<<"------------------------------------------------------"<<endl;
		return 1;
	}
};

int _tmain(int argc, _TCHAR* argv[])
{
	testing::InitGoogleTest(&argc, argv);
	return RUN_ALL_TESTS();
}

class VibrationTest : public testing::Test
{
protected:
	static void SetUpTestCase()
	{
		vib = new Vibration();
		cout<<"start"<<endl;
	}
	static void TearDownTestCase()
	{
		delete vib;
	}
	static Vibration* vib;
};
Vibration* VibrationTest::vib = NULL;

TEST_F(VibrationTest,INITIAL)
{
	EXPECT_EQ(1,vib->initial());
}

TEST_F(VibrationTest,VIBRATE)
{
	EXPECT_EQ(1,vib->vibrate());
}
